﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="PaymentByList.aspx.cs" Inherits="PaymentByList"  EnableEventValidation="false"%>
<%@ Register TagPrefix="ajax" Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit"%>
<%@ Register TagPrefix="fw" TagName="FilterControl" Src="~/Controls/FilterWindow.ascx" %>
<%@ Register TagPrefix="cpf" TagName="ContractsPrintForm" Src="~/Controls/ContractsPrintForm_Control.ascx" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
    <script type="text/javascript" src="../Scripts/jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="../Scripts/jquery.helper.js"></script>
    <script type="text/javascript" language="javascript">

        var newLine = '\n\r';

        var isDebugD = false;    //fDiffPeriod
        var isDebugF = true;    //fGetValueFromCell
        var isDebugC = false;    //fCalculateTotals
        var isDebugP = false;    //fParseFloat
        var isDebugS = true;    //fSetCellValue
        var isDebugV = false;    //fCalcCurs

        var tagSpan = 0;
        var tagInput = 1;
        
        function roundNumber(num, dec) {
            var result = Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
            return result;
        }

        function fSetColorToCell(indexRow, colIndex, typeTag, value) {
            var grid = document.getElementById('<%= newCalculatedOrdersGridView.ClientID %>');
            var msgS = 'Start fSetColorToCell';
            var tagColor = "green";
            
            if (roundNumber(value, 2) < 0) {
                tagColor = "red";
            }
            
            switch (typeTag) {
                case 0:
                    msgS += 'Case 0' + newLine;
                    grid.rows[indexRow].cells[colIndex].getElementsByTagName('span')[0].style.color = tagColor;
                    break;
                case 1:
                    msgS += 'Case 1' + newLine;
                    grid.rows[indexRow].cells[colIndex].getElementsByTagName('input')[0].style.color = tagColor;
                    break;
            }
            if (isDebugS) {
                alert(msgS);
            }
        }

        function fSetValueToCell(indexRow, colIndex, typeTag, value) {
            var grid = document.getElementById('<%= newCalculatedOrdersGridView.ClientID %>');
            var msgS = 'Start fSetValueToCell';

            switch (typeTag) {
                case 0:
                    msgS += 'Case 0' + newLine;
                    grid.rows[indexRow].cells[colIndex].getElementsByTagName('span')[0].innerHTML = roundNumber(value, 2);
                    break;
                case 1:
                    msgS += 'Case 1' + newLine;
                    grid.rows[indexRow].cells[colIndex].getElementsByTagName('input')[0].value = roundNumber(value, 2);
                    break;
            }
            if (isDebugS) {
                alert(msgS);
            }
        }

        function fGetValueFromCell(indexRow, colIndex, typeTag) {
            var grid = document.getElementById('<%= newCalculatedOrdersGridView.ClientID %>');

            var msgF = 'Start fGetValueFromCell' + newLine;
            
            var result;

            msgF += 'typeTag: ' + typeTag + newLine;
            msgF += 'colIndex: ' + colIndex + newLine;
            msgF += 'indexRow: ' + indexRow + newLine;
            
            typeTag = parseInt(typeTag);
            indexRow = parseInt(indexRow);
            colIndex = parseInt(colIndex);

            switch (typeTag) {
                case 0:
                    msgF += 'Case 0' + newLine;
                    result = grid.rows[indexRow].cells[colIndex].getElementsByTagName('span')[0].innerHTML;

                    break;
                case 1:
                    result = grid.rows[indexRow].cells[colIndex].getElementsByTagName('input')[0].value;
                    msgF += 'Case 1' + newLine;
                    break;
            }

            msgF += 'result: ' + result + newLine;

            if (isDebugF) {
                alert(msgF);
            }
            result = fParseFloat(result);
            return result;
        }

        function fCalcCurs(t) {
            var indexRow = t.parentNode.parentNode.rowIndex;
            var msgV = 'Start fCalcCurs' + newLine;
            msgV += 'indexRow: ' + indexRow + newLine;

            var cursValue = fGetValueFromCell(indexRow, 7, tagInput);
            msgV += 'Curs valutar: ' + cursValue + newLine;

            var mainValue = fGetValueFromCell(indexRow, 4, tagSpan);
            msgV += 'mainValue: ' + mainValue + newLine;

            var procentValue = fGetValueFromCell(indexRow, 3, tagSpan);
            msgV += 'procentValue: ' + procentValue + newLine;

            var mainByCurs = mainValue * cursValue;
            msgV += 'mainByCurs: ' + mainByCurs + newLine;

            var procentByCurs = procentValue * cursValue;
            msgV += 'procentByCurs: ' + procentByCurs + newLine;

            fSetValueToCell(indexRow, 8, tagSpan, mainByCurs);

            fSetValueToCell(indexRow, 9, tagSpan, procentByCurs);

            fSetValueToCell(indexRow, 10, tagSpan, procentByCurs+mainByCurs);

            fCalculateTotals(t, 1);

            if (isDebugV) {
                alert(msgV);
            }
        }

        function fCalculateTotals(t, indexCell) {

            var indexRow = t.parentNode.parentNode.rowIndex;

            //var grid = document.getElementById('<%= newCalculatedOrdersGridView.ClientID %>');

            var msgC = 'Start: fCalculateTotals' + newLine;
            msgC +='Index row: ' + indexRow +newLine;
            msgC += 'Index cell: ' + indexCell + newLine;
            
            var hiddenObj = document.getElementById('<%= rowHiddenValueID.ClientID %>');
            msgC += 'Hidden obj: ' + hiddenObj.value + newLine;
           
            var avansValue = 0.00;
            if (indexRow > 1) {
                avansValue = fGetValueFromCell(indexRow - 1, 18, tagInput);
                msgC += 'indexRow >1 ' + newLine;
            }
            msgC += 'Diferenta before: ' + avansValue + newLine;

            var cursValue = fGetValueFromCell(indexRow, 7, tagInput);
            
            var incasatValue = fGetValueFromCell(indexRow, 13, tagInput);
            msgC += 'Incasat value: ' + incasatValue + newLine;

            var inputValue = parseFloat(incasatValue) + parseFloat(avansValue);
            msgC += 'Input: ' + inputValue + newLine;

            var dobindaValue = fGetValueFromCell(indexRow, 15, tagInput);
            msgC += 'Dobinda: ' + dobindaValue + newLine;
            
            var principalValue = fGetValueFromCell(indexRow, 16, tagInput);
            msgC += 'Principal :' + principalValue + newLine;
            
            var totalValue = fGetValueFromCell(indexRow, 17, tagInput);
            msgC += 'Total spre plata: ' + totalValue + newLine;

            var tcp = parseFloat(0.00);
            var diferentaValue = fGetValueFromCell(indexRow, 18, tagInput); 
            var penalitateValue = parseFloat(0.00);
            var difPercentValue = parseFloat(0.00);
            var mainRate = parseFloat(0.00);
            var difMainValue = parseFloat(0.00);

            var penaltyValue = fParseFloat(document.getElementById('<%= creditDetPenaltyValueLabel.ClientID %>').innerHTML);
            msgC += 'Penalty: ' + penaltyValue + newLine;
            
            var delayDaysCount = fGetValueFromCell(indexRow, 12, tagSpan);
            msgC += 'Delay days: ' + delayDaysCount + newLine;

            msgC += 'Start switch' + newLine;

            var varPercent = fGetValueFromCell(indexRow, 3, tagSpan);
            varPercent = varPercent * cursValue; 
            msgC += 'varPercent: ' + varPercent + newLine;

            var varMain = fGetValueFromCell(indexRow, 4, tagSpan);
            varMain = varMain * cursValue;
            msgC += 'varMain: ' + varMain + newLine;

            var creditValue = parseFloat(varPercent) + parseFloat(varMain);
            msgC += 'creditValue: ' + creditValue + newLine;

            switch (indexCell) {
                case 0:
                    msgC += 'Case_0' + newLine;
                  
                    penalitateValue = ((creditValue * parseFloat(penaltyValue)) / 100) * parseFloat(delayDaysCount);

                    break;
                case 1:
                    msgC += 'Case_1' + newLine;

                    penalitateValue = fGetValueFromCell(indexRow, 14, tagInput);
                    
                    break;
                
            }
            if (parseFloat(penalitateValue) < 0) {
                penalitateValue = 0;
            }
            msgC += 'penalitateValue: ' + penalitateValue + newLine;

            if (varPercent <= inputValue) {
                msgC += 'varPercent<=incasatValue' + newLine;
                dobindaValue = varPercent;

                var difIncasat = inputValue - varPercent;
                msgC += 'difIncasat: ' + difIncasat + newLine;

                if (varMain <= difIncasat) {
                    msgC += 'varMain<=difIncasat' + newLine;
                    mainRate = varMain;
                    difMainValue = 0;
                }
                else {
                    msgC += 'varMain>difIncasat' + newLine;
                    difMainValue = inputValue - creditValue;
                    mainRate = varMain + ((creditValue - inputValue) * (-1));
                }
                msgC += 'difMainValue: ' + difMainValue + newLine;
                msgC += 'mainRate: ' + mainRate + newLine;
            }
            else {

                dobindaValue = inputValue;
                difPercentValue = (varPercent - inputValue) * (-1);
                msgC += 'difPercentValue: ' + difPercentValue + newLine;

                mainRate = 0;
                difMainValue = varMain * (-1);
                msgC += 'difMainValue: ' + difMainValue + newLine;
            }


            tcp = parseFloat(penalitateValue) + (parseFloat(dobindaValue)) + (parseFloat(mainRate)) - parseFloat(avansValue);
            msgC += 'tcp: ' + tcp + newLine;
            diferentaValue = parseFloat(incasatValue) + parseFloat(avansValue) - parseFloat(penalitateValue) - (parseFloat(dobindaValue) - difPercentValue) - (parseFloat(mainRate) - difMainValue);
            msgC += 'diferentaValue: ' + diferentaValue + newLine;

            if (isDebugC) {
                alert(msgC);
            }

            fSetValueToCell(indexRow, 14, tagInput, penalitateValue);
            
            fSetValueToCell(indexRow, 15, tagInput, dobindaValue);
            
            fSetValueToCell(indexRow, 15, tagSpan, difPercentValue);
            
            fSetColorToCell(indexRow, 15, tagSpan, difPercentValue);
            
            fSetValueToCell(indexRow, 16, tagInput, mainRate);
            
            fSetValueToCell(indexRow, 16, tagSpan, difMainValue);
            fSetColorToCell(indexRow, 16, tagSpan, difMainValue);
            
            fSetValueToCell(indexRow, 17, tagInput, tcp);
            
            fSetValueToCell(indexRow, 18, tagInput, diferentaValue);
            
            fSetColorToCell(indexRow, 18, tagInput, diferentaValue);
           
            hiddenObj = roundNumber(penalitateValue, 2) + '|'
            + roundNumber(dobindaValue, 2) + '|'
            + roundNumber(mainRate, 2) + '|'
            + delayDaysCount + '|'
            + roundNumber(diferentaValue, 2);

            document.getElementById('<%= rowHiddenValueID.ClientID %>').value = hiddenObj;
            
        }

        function fParseFloat(cellValue) {
            var msgP = 'Start: Parse float function' + newLine;
            msgP += 'Input cellValue: ' + cellValue + newLine;
            if (parseFloat(cellValue)) {
                cellValue = parseFloat(cellValue);
                msgP+='PFF: if is parseFloat'+newLine;
                if (cellValue == NaN) {
                    msgP+='percentValue is NaN'+newLine;
                    cellValue = parseFloat(0.00);
                }
            }
            else {
                cellValue = parseFloat(0.00);
                msgP+='PFF: is not parseFloat, cellValue=0'+newLine;
            }

            msgP += 'End: Parse float function' + newLine;
            msgP += 'Cell Value return: ' + cellValue + newLine;
            if (isDebugP) {
                alert(msgP);
            }
            return cellValue;
        }

        function fDiffPeriod(t) {
            var grid = document.getElementById('<%= newCalculatedOrdersGridView.ClientID %>');

            var msgD = 'Start DiffPeriod' + newLine;
            
            var indexRow = t.parentNode.parentNode.rowIndex;
            msgD += 'indexRow: ' + indexRow + newLine;

            var getDate1 = grid.rows[indexRow].cells[1].getElementsByTagName('span')[0].innerHTML;
            //fGetValueFromCell(indexRow, 1, tagSpan);
            msgD += 'getDate1: ' + getDate1 + newLine;
            
            var getDate2 = grid.rows[indexRow].cells[11].getElementsByTagName('input')[0].value;
            // fGetValueFromCell(indexRow, 11, tagInput);
            msgD += 'getDate2: ' + getDate2 + newLine;

            var t1 = new Date(getDate1.replace(/(\d{2})\.(\d{2})\.(\d{4})/, '$3-$2-$1'));
            msgD += 't1: ' + t1 + newLine;

            var t2 = new Date(getDate2.replace(/(\d{2})\.(\d{2})\.(\d{4})/, '$3-$2-$1'));
            msgD += 't2: ' + t2 + newLine;

            var difPeriod = parseInt((t2 - t1) / (24 * 3600 * 1000));
            msgD += 'difPeriod: ' + difPeriod + newLine;

            fSetValueToCell(indexRow, 12, tagSpan, difPeriod);

            if (isDebugD) {
                alert(msgD);
            }

            fCalculateTotals(t, 0);
        }
    </script> 
    </asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">

    <asp:Panel ID="emptyPanel" runat="server" visible="false">
        <div align="center">
            <h1 >Achitarea creditului</h1>
        </div>
    </asp:Panel>

    <asp:HiddenField ID="selectedLoanID_HiddenField" runat="server" />
    <asp:HiddenField ID="selectedLoanVersion_HiddenField" runat="server" />

    <asp:Panel ID = "viewCreditDetailsPanel" runat="server" Visible="false" >     
        <asp:Panel ID="loanDetailsPanel" runat="server">
        <div class="table" style="width:100%;">
            <div class="row">
                <div class="cell infoTableLeft"> <asp:Label ID="Label25" runat="server" Text="Codul Contractului:"></asp:Label></div>
                <div class="cell infoTableRigth"> <asp:Label ID="creditDetContractCodeLabel" runat="server" Text=""></asp:Label></div>
                <div class="cell infoTableLeft"> <asp:Label ID="Label15" runat="server" Text="Procentul initial:"></asp:Label></div>
                <div class="cell infoTableRigth"> <asp:Label ID="creditDetPercentValueLabel" runat="server" Text=""></asp:Label></div>
                <div class="cell infoTableLeft"> <asp:Label ID="Label10" runat="server" Text="Linia de creditare:"></asp:Label></div>
                <div class="cell infoTableRigth"> <asp:Label ID="credtDetFoundingLineLabel" runat="server" Text=""></asp:Label></div>
            </div>
            <div class="row">                
                <div class="cell infoTableLeft"> <asp:Label ID="Label9" runat="server" Text="Clientul:"></asp:Label></div>
                <div class="cell infoTableRigth"> <asp:HyperLink ID="creditDetClientDescriptionHyperLink" runat="server"></asp:HyperLink> </div>
                <div class="cell infoTableLeft"> <asp:Label ID="Label16" runat="server" Text="Calcularea Procentului din:"></asp:Label></div>
                <div class="cell infoTableRigth"> <asp:Label ID="creditDetCalculatePercentFromLabel" runat="server" Text=""></asp:Label></div>
                <div class="cell infoTableLeft"> <asp:Label ID="Label20" runat="server" Text="Scopul Creditului:"></asp:Label></div>
                <div class="cell infoTableRigth"> <asp:Label ID="creditDetLoanScopeLabel" runat="server" Text=""></asp:Label></div>
            </div>            
            <div class="row" >
                <div class="cell infoTableLeft"><asp:Label ID="Label12" runat="server" Text="Credit Start date:"></asp:Label></div>
                <div class="cell infoTableRigth"><asp:Label ID="creditDetLoanStartDateLabel" runat="server" Text=""></asp:Label> </div>
                <div class="cell infoTableLeft"> <asp:Label ID="Label17" runat="server" Text="Penalitatea in marimea de:"></asp:Label></div>
                <div class="cell infoTableRigth"> <asp:Label ID="creditDetPenaltyValueLabel" runat="server" Text=""></asp:Label></div>
                <div class="cell infoTableLeft"> <asp:Label ID="Label21" runat="server" Text="Persoana de garant:"></asp:Label></div>
                <div class="cell infoTableRigth"> <asp:Label ID="creditDetGarantorIDLabel" runat="server" Text=""></asp:Label></div>
            </div>           
            <div class="row" >
                <div class="cell infoTableLeft"> <asp:Label ID="Label11" runat="server" Text="Credit End date:"></asp:Label></div>
                <div class="cell infoTableRigth"> <asp:Label ID="credtDetLoanEndDateLabel" runat="server" Text=""></asp:Label></div>
                <div class="cell infoTableLeft"> <asp:Label ID="Label18" runat="server" Text="Calcularea Penalitatii din:"></asp:Label></div>
                <div class="cell infoTableRigth"> <asp:Label ID="creditDetCalclatePEnaltyFromLabel" runat="server" Text=""></asp:Label></div>
                <div class="cell infoTableLeft"> <asp:Label ID="Label22" runat="server" Text="Gajul:"></asp:Label></div>
                <div class="cell infoTableRigth"> <asp:Label ID="creditDetPledgeLabel" runat="server" Text=""></asp:Label></div>
            </div>            
            <div class="row" >
                <div class="cell infoTableLeft"> <asp:Label ID="Label14" runat="server" Text="Nr. initial de luni:"></asp:Label></div>
                <div class="cell infoTableRigth"><asp:Label ID="creditDetNrOfCreditMonthLabel" runat="server" Text=""></asp:Label></div>
                <div class="cell infoTableLeft"> <asp:Label ID="Label19" runat="server" Text="Perioada de gratie pentru penalitate (zile):"></asp:Label></div>
                <div class="cell infoTableRigth"> <asp:Label ID="creditDetpenaltyGracePeriodLabel" runat="server" Text=""></asp:Label></div>
                <div class="cell infoTableLeft"> <asp:Label ID="Label23" runat="server" Text="Categoria Contractului:"></asp:Label></div>
                <div class="cell infoTableRigth"> <asp:Label ID="creditDetLoanCategoryLabel" runat="server" Text=""></asp:Label></div>
            </div>            
            <div class="row">
                <div class="cell infoTableLeft"><asp:Label ID="Label13" runat="server" Text="Summa creditarii:"></asp:Label> </div>
                <div class="cell infoTableRigth"> <asp:Label ID="creditDetCreditAmountLabel" runat="server" Text=""></asp:Label></div>
                <div class="cell infoTableLeft"> <asp:Label ID="Label26" runat="server" Text="Periodicitatea initiala:"></asp:Label></div>
                <div class="cell infoTableRigth"><asp:Label ID="initialPeriodLabel" runat="server" Text=""></asp:Label> </div>
                <div class="cell infoTableLeft"> <asp:Label ID="Label24" runat="server" Text="Ultima Modificare:"></asp:Label></div>
                <div class="cell infoTableRigth"> <asp:Label ID="creditDetLastModificationBYLabel" runat="server" Text=""></asp:Label></div>
            </div>
        </div>
        
        <br />
            <asp:Button runat="server" ID="backButtonID" Text="Back" Visible="true" onclick="backButton_Click"  />                     
           
       </asp:Panel>
        <asp:HiddenField ID="rowHiddenValueID" runat="server" />
        <asp:GridView ID="newCalculatedOrdersGridView" runat="server" 
            EnableModelValidation="True" 
            AutoGenerateColumns="False" 
            ShowFooter="True" 
            CssClass="mGrid"
            PagerStyle-CssClass="pgr"         
            AlternatingRowStyle-CssClass="alt"   
            SelectedRowStyle-BackColor="#CCCCFF"       
            OnRowUpdating="newCalculatedOrdersGridView_RowUpdating"   
            OnRowDeleting="newCalculatedOrdersGridView_RowDeleting"              
            OnRowDataBound="newCalculatedOrdersGridView_RowDataBound" RowStyle-HorizontalAlign="Right">
            <Columns>
                <asp:BoundField DataField="nr"  HeaderText="Nr"  HtmlEncode="False" />
                
                <asp:TemplateField HeaderText="Data">
                    <ItemTemplate>
                        <asp:Label ID="calculatedDataLabel" runat="server" Text='<%# ((Eval("calculatedData") != null && Eval("calculatedData") is DateTime) ?  ((DateTime)Eval("calculatedData")).ToString(Constants.Constants.ISODateBackwardDotsFormat) : "") %>' ></asp:Label>
                    </ItemTemplate>
                    <FooterTemplate>
                        <asp:Label ID="totalLabel" runat="server" Text="Totaluri:"></asp:Label>
                    </FooterTemplate>
                </asp:TemplateField >
                                
                <asp:TemplateField HeaderText="Sold initial">
                    <ItemTemplate>                       
                        <asp:Label ID="remainingAmountLabel" runat="server" Text='<%# Bind("remainingAmount") %>'></asp:Label> 
                    </ItemTemplate>
                    <FooterTemplate>
                    </FooterTemplate>
                </asp:TemplateField>   
                
                <asp:TemplateField HeaderText="Dobinda">
                    <ItemTemplate>
                        <asp:Label ID="percentValueLabel" runat="server" Text='<%# Bind("percentValue") %>' />
                    </ItemTemplate>                   
                    <FooterTemplate>
                        <asp:Label ID="totalPercentLabel" runat="server" Text="" CssClass="tableFooter"/>
                    </FooterTemplate>
                </asp:TemplateField>  
                
                <asp:TemplateField HeaderText="Principala">
                    <ItemTemplate>                       
                        <asp:Label ID="mainRateLabel" runat="server" Text='<%# Bind("mainRate") %>'></asp:Label> 
                    </ItemTemplate>                   
                    <FooterTemplate>
                        <asp:Label ID="totalMainRateLabel" runat="server" Text="" CssClass="tableFooter"></asp:Label>
                    </FooterTemplate>
                </asp:TemplateField>                
                
                <asp:TemplateField HeaderText="Anuitate">
                    <ItemTemplate>                       
                        <asp:Label ID="totalAmountLabel" runat="server" Text='<%# Bind("totalAmount") %>'></asp:Label> 
                    </ItemTemplate>                   
                    <FooterTemplate>
                        <asp:Label ID="totalAnuitateLabel" runat="server" Text="" CssClass="tableFooter"></asp:Label>
                    </FooterTemplate>
                </asp:TemplateField>

                <asp:TemplateField HeaderText="Sold final">
                    <ItemTemplate>
                        <asp:Label ID="finalSoldLabel" runat="server" Text='<%# Bind("SoldFinal") %>' CssClass="inputRight"></asp:Label>
                    </ItemTemplate>
                    <FooterTemplate>
                        
                    </FooterTemplate>
                </asp:TemplateField>   

                <asp:TemplateField HeaderText="Curs Valutar">
                    <ItemTemplate>
                        <asp:TextBox runat="server" ID="currencyChangeRateInputID" Text='<%# Bind("currencyChangeRate") %>' CssClass="inputRight inputTransparent" onChange="fCalcCurs(this);"></asp:TextBox>                        
                    </ItemTemplate>
                    <FooterTemplate>
                        
                    </FooterTemplate>
                </asp:TemplateField>   

                <asp:TemplateField HeaderText="Corp Credit MDL">
                    <ItemTemplate>
                        <asp:Label ID="mainRate_RatedLabel" runat="server" Text='<%# Bind("mainRate_Rated") %>'></asp:Label>
                    </ItemTemplate>
                    <FooterTemplate>
                        <asp:Label ID="totalMainRateRatedLabel" runat="server" Text=""></asp:Label>
                    </FooterTemplate>
                </asp:TemplateField> 

                <asp:TemplateField HeaderText="Dobinda MDL">
                    <ItemTemplate>
                        <asp:Label ID="percentValue_RatedLabel" runat="server" Text='<%# Bind("percentValue_Rated") %>'></asp:Label>
                    </ItemTemplate>
                    <FooterTemplate>
                        
                    </FooterTemplate>
                </asp:TemplateField> 

                <asp:TemplateField HeaderText="Suma Totala MDL">
                    <ItemTemplate>
                        <asp:Label ID="totalAmount_RatedLabel" runat="server" Text='<%# Bind("totalAmount_Rated") %>'></asp:Label>
                    </ItemTemplate>
                    <FooterTemplate>
                        <asp:Label ID="totalAmount_RatedLabel" runat="server" Text=""></asp:Label>
                    </FooterTemplate>
                </asp:TemplateField> 

                <asp:TemplateField HeaderText="Data platii">
                    <ItemTemplate>
                        <asp:TextBox Enable='<%# ((Eval("payedOrderNumber")!=null)? true : false) %>' 
                            ID="payedDateTextBoxID" 
                            runat="server" 
                            CssClass="inputRight inputTransparent" onChange="fDiffPeriod(this);"
                            Text='<%# ((Eval("payedDate") != null && Eval("payedDate") is DateTime) ?  ((DateTime)Eval("payedDate")).ToString(Constants.Constants.ISODateBackwardDotsFormat) : "") %>' ></asp:TextBox>                       
                        <ajax:CalendarExtender ID="payedCalendarExtenderID" runat="server" TargetControlID="payedDateTextBoxID" Format="<%# Constants.Constants.ISODateBackwardDotsFormat %>" />
                    </ItemTemplate>
                </asp:TemplateField>                      
     
                <asp:TemplateField HeaderText="Intirzieri (zile)" ItemStyle-HorizontalAlign="Right">
                    <ItemTemplate>                       
                        <asp:Label ID="additionalPaysCommentLabel" runat="server" Text='<%# Bind("additionalPaysComment") %>'></asp:Label> 
                    </ItemTemplate>                                    
                </asp:TemplateField>                                      
                
                <asp:TemplateField HeaderText="Incasat">
                    <ItemTemplate>
                        <asp:TextBox runat="server" ID="incassaPays" Text='<%# Bind("input_Pays") %>' onChange="fCalculateTotals(this,1);" CssClass="inputRight inputTransparent" ></asp:TextBox>                        
                    </ItemTemplate>
                </asp:TemplateField>
                 
                <asp:TemplateField HeaderText="Penalitate">
                    <ItemTemplate>
                        <asp:TextBox runat="server" ID="additionalPays" Text='<%# Bind("additionalPays") %>' CssClass="inputRight inputTransparent" onKeyUp="fCalculateTotals(this,1);"></asp:TextBox>
                    </ItemTemplate>
                    <FooterTemplate>
                        <asp:Label ID="totalAdditionalPaysLabel" runat="server" Text="" CssClass="tableFooter"></asp:Label>
                    </FooterTemplate>
                </asp:TemplateField>
                 
                <asp:TemplateField HeaderText="Dobinda">
                    <ItemTemplate>
                         <asp:TextBox runat="server" ID="procentPaymentValueTextBoxID" CssClass="inputRight inputTransparent" Text='<%# Bind("percentValue_Pays") %>' ReadOnly="false"></asp:TextBox>
                         <asp:Label ID="procentPaymentDifLabel" runat="server" Text='<%# Bind("difDobinda") %>'></asp:Label>
                    </ItemTemplate>                   
                    <FooterTemplate>
                        <asp:Label ID="totalProcentPaymentLabel" runat="server" Text=""  CssClass="tableFooter"/>
                    </FooterTemplate>
                </asp:TemplateField>  
                
                <asp:TemplateField HeaderText="Principal">
                    <ItemTemplate> 
                        <asp:TextBox runat="server" ID="ratePaymentTextBoxID" CssClass="inputRight inputTransparent" Text='<%# Bind("mainRate_Pays") %>' ReadOnly="false"></asp:TextBox>
                        <asp:Label ID="ratePaymentDifLabel" runat="server" Text='<%# Bind("difMain") %>'></asp:Label>
                    </ItemTemplate>                   
                    <FooterTemplate>
                        <asp:Label ID="totalRatePaymentPrincipalaLabel" runat="server" Text="" CssClass="tableFooter"></asp:Label>
                    </FooterTemplate>
                </asp:TemplateField>                
    
                <asp:TemplateField HeaderText="Total catre plata">
                    <ItemTemplate> 
                        <asp:TextBox runat="server" ID="totalPaymentTextBoxID" CssClass="inputRight inputTransparent" Text='<%# Bind("totalPaymentAmount") %>' ReadOnly="true"></asp:TextBox>
                    </ItemTemplate>                   
                    <FooterTemplate>
                        <asp:Label ID="totalTotalPaymentPrincipalaLabel" runat="server" Text="" CssClass="tableFooter"></asp:Label>
                    </FooterTemplate>
                </asp:TemplateField>                
    
                <asp:TemplateField HeaderText="Diferenta">
                    <ItemTemplate>
                        <asp:TextBox runat="server" ID="difPaymentTextBoxID" CssClass="inputRight inputTransparent" Text='<%# Bind("diference_Pays") %>' ReadOnly="true"></asp:TextBox>                
                    </ItemTemplate>                   
                    <FooterTemplate>
                        <asp:Label ID="totalDifPaymentPrincipalaLabel" runat="server" Text="" CssClass="tableFooter"></asp:Label>
                    </FooterTemplate>
                </asp:TemplateField>                
                          
                <asp:TemplateField HeaderText="Nr. Ordin de plata">
                    <ItemTemplate>
                        <asp:Label ID="payedOrderNumberLabel" runat="server" Text='<%# Bind("payedOrderNumber") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField> 
                               
                <asp:ButtonField ButtonType="Button"  CommandName="Update" Text="x" HeaderText="Update" /> 
                <asp:ButtonField ButtonType="Button" CommandName="Delete" Text="--" HeaderText="Anulare" />
                
            </Columns>
        </asp:GridView>       
    </asp:Panel>
    
</asp:Content>

